package models;

import java.util.List;

import siena.Generator;
import siena.Id;
import siena.Model;
import siena.Query;

public class OutboxMessage extends Model {
	@Id(Generator.AUTO_INCREMENT)
	public Long id;
	
	public User owner;
	
	public Message message;

	public Boolean readed;
	
	public Boolean deleted;
	
	public OutboxMessage(User owner, Message message) {
		this.owner = owner;
		this.message = message;
		this.readed = Boolean.FALSE;
		this.deleted = Boolean.FALSE;
	}
	
	public OutboxMessage(User owner, Message message, Boolean readed, Boolean deleted) {
		this.owner = owner;
		this.message = message;
		this.readed = readed;
		this.deleted = deleted;
	}
	
	public static Query<OutboxMessage> all() {
		return all(OutboxMessage.class);
	}
	
	public static Query<OutboxMessage> findSent(User from) {
		return all().filter("owner", from);
	}
	
	public static int countSent(User from) {
		return findSent(from).count();
	}
	
	public static OutboxMessage getSent(Long id, User from) {
		return findSent(from).filter("id", id).get();
	}
	
	public static List<OutboxMessage> paginate(Query<OutboxMessage> query, int offset, int limit) {
		return query.fetch(limit, offset);
	}
}
